Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2AudioManager = require("AudioManager");
var $2GameEvent = require("GameEvent");
var $2UIHelp = require("UIHelp");
var $2GameUser = require("GameUser");
var $2ServerConfig = require("ServerConfig");
var $2ConstValue = require("ConstValue");
var def_TT_VideoMgr = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this._rewardVideoAd = new Map();
    this._rewardcomplat = new Map();
    this.playing = false;
  }
  return babel_createClass(_ctor, [{
    key: "Create",
    value: function Create(e, t) {
      var _this87 = this;
      var n = e.videoid;
      this._rewardcomplat.set(n, t);
      var _c = this;
      if (0 == this._rewardVideoAd.has(n)) {
        var _t47 = window.tt.createRewardedVideoAd({
          adUnitId: n,
          multiton: true
        });
        _t47.onError(function (t) {
          $2GameEvent.default.sendEvent("adevent", {
            type: "video",
            action: "get",
            result: "fail",
            adid: n,
            origin: e.origin,
            level: e.level
          });
          _this87.playing = false;
          $2UIHelp.UIHelp.showTip("广告拉取失败");
          cc.game.resume();
          $2AudioManager.AudioManager.getInstance().resumeAll();
          var a = _c._rewardcomplat.get(n);
          null != a && a(t.errCode);
          _this87.destroy(n);
        });
        _t47.onClose(function (t) {
          cc.game.resume();
          $2AudioManager.AudioManager.getInstance().resumeAll();
          _this87._rewardVideoAd.get(n).showing = false;
          if (t && t.isEnded) {
            $2GameEvent.default.sendEvent("adevent", {
              type: "video",
              action: "finish",
              result: "success",
              adid: n,
              origin: e.origin,
              level: e.level
            });
            _this87.playing = false;
            var _t48 = new Date().getTime() + 1e3 * $2ServerConfig.default.getInstance().gameconfig.config.openInterstitialtime;
            _t48 > $2GameUser.default.getInstance().InterstitialCanShowTime && ($2GameUser.default.getInstance().InterstitialCanShowTime = _t48);
            console.log("data:", e);
            $2GameEvent.default.userSeeVideoData(e.origin, e.level);
            var _o99 = _c._rewardcomplat.get(n);
            if (null != _o99) {
              _o99(true);
              cc.director.emit("MYSELF_TOUCH_END", "playok");
            }
            $2ConstValue.ConstValue.InterAdIntervalTime += $2ConstValue.ConstValue.INCENTIVE_VIDEO_INTERVAL_TT;
          } else {
            $2GameEvent.default.sendEvent("adevent", {
              type: "video",
              action: "finish",
              result: "fail",
              adid: n,
              origin: e.origin,
              level: e.level
            });
            var _t49 = _c._rewardcomplat.get(n);
            if (null != _t49) {
              _t49(false);
              cc.director.emit("MYSELF_TOUCH_END", "playfail");
            }
            console.log("中途退出");
          }
          _this87.destroy(n);
        });
        this._rewardVideoAd.set(n, _t47);
      }
    }
  }, {
    key: "destroy",
    value: function destroy(e) {
      if (this._rewardVideoAd.has(e)) {
        this._rewardVideoAd.get(e).destroy();
        this._rewardVideoAd.delete(e);
        this._rewardcomplat.delete(e);
      }
    }
  }, {
    key: "playvideo",
    value: function playvideo(e, t) {
      var _this88 = this;
      0 == this.playing && (this.playing = true);
      console.log("播放视频数据。。。。。。。。。。。。:", e);
      var n = e.videoid;
      this.Create(e, t);
      this._rewardVideoAd.get(n).show().then(function () {
        $2GameEvent.default.sendEvent("adevent", {
          type: "video",
          action: "show",
          result: "success",
          adid: n,
          origin: e.origin,
          level: e.level
        });
        cc.game.pause();
        $2AudioManager.AudioManager.getInstance().pauseAll();
      }).catch(function () {
        _this88._rewardVideoAd.get(n).load().then(function () {
          $2GameEvent.default.sendEvent("adevent", {
            type: "video",
            action: "get",
            result: "success",
            adid: n,
            origin: e.origin,
            level: e.level
          });
          _this88._rewardVideoAd.get(n).show().then(function () {
            $2GameEvent.default.sendEvent("adevent", {
              type: "video",
              action: "show",
              result: "success",
              adid: n,
              origin: e.origin,
              level: e.level
            });
            cc.game.pause();
            $2AudioManager.AudioManager.getInstance().pauseAll();
          }).catch(function () {
            _this88.playing = false;
            $2GameEvent.default.sendEvent("adevent", {
              type: "video",
              action: "show",
              result: "fail",
              adid: n,
              origin: e.origin,
              level: e.level
            });
          });
        }).catch(function () {
          $2GameEvent.default.sendEvent("adevent", {
            type: "video",
            action: "get",
            result: "fail",
            adid: n,
            origin: e.origin,
            level: e.level
          });
          $2UIHelp.UIHelp.showTip("拉取失败,请再次尝试!");
          _this88.playing = false;
        });
      });
    }
  }], [{
    key: "Instance",
    get() {
      _ctor._instance || (_ctor._instance = new _ctor());
      return _ctor._instance;
    }
  }]);
}();
exports.default = def_TT_VideoMgr;